const Service = require('egg').Service;


module.exports = class WeatherService extends Service {
    async weatherInfo({city, extensions = 'base'}) {
        const {ctx} = this;
        const key = '482812b26d4f0a0af70e5f2adf2dc886';
        const resp = await ctx.curl(`https://restapi.amap.com/v3/weather/weatherInfo?key=${key}&city=${city}&extensions=${extensions}`);
        const data = JSON.parse(resp.data?.toString());
        if (extensions === 'all') {
            return data?.forecasts?.[0]?.casts;
        }
        return data?.lives?.[0];
    }
}
